//
//  HZGoodsParametersCell.m
//  app
//
//  Created by 刘华舟 on 15/6/23.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "HZGoodsParametersCell.h"
#import "HZTableView.h"

#import "NSString+Conveniently.h"

const static NSInteger kGoodsParametersCellLabelWidth = 160/2;
@interface HZGoodsParametersCell()

@property (strong, nonatomic) UILabel *nameLabel;
@property (strong, nonatomic) UILabel *valueLabel;

@end

@implementation HZGoodsParametersCell

-(void)drawRect:(CGRect)rect
{
    [self drawBackground:self.bounds color:[UIColor whiteColor]];
    [self drawHorizonLineLeft:[self.ubo uw:kSizeMallViewMargin] right:[self.ubo ow:0] at:[self.ubo fh:UB_BOTTOM ph:-0.5]];
}

+ (instancetype)cellWithTableView:(HZTableView *)tableView{
    NSString *cellReuseIdentifier = @"HZGoodsParametersCell";
    
    HZGoodsParametersCell * cell= (HZGoodsParametersCell *)[tableView dequeueReusableCellWithIdentifier:cellReuseIdentifier];
    if (cell == nil) {
        cell = [[HZGoodsParametersCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellReuseIdentifier];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.contentMode = UIViewContentModeRedraw;
        
        self.frame = CGRectOf([self.ubo fx:UB_LEFT fy:UB_TOP], [UBO_SCREEN fw:UB_WIDTH oh:kHZGoodsParametersCellHeight]);
        
        self.backgroundColor = HZ_WHITE_COLOR;
        
        
        self.nameLabel = [[UILabel alloc] initWithFrame:CGRectOf([self.ubo fx:UB_LEFT ux:kSizeMallViewMargin fy:UB_TOP oy:kSizeMallViewMargin/2],
                                                                 [self.ubo ow:kGoodsParametersCellLabelWidth fh:UB_HEIGHT oh:-kSizeMallViewMargin])];
        
        
        self.nameLabel.textAlignment = NSTextAlignmentLeft;
        self.nameLabel.textColor = HZ_MALL_TEXT_BLACK_COLOR;
        self.nameLabel.font = JKAppGlobleFontSmallTagText;
        [self.nameLabel setAdjustsFontSizeToFitWidth:YES];
        [self addSubview:self.nameLabel];
        
        self.valueLabel = [[UILabel alloc] initWithFrame:CGRectOf([self.nameLabel.ufo fx:UB_RIGHT ux:kSizeMallViewMargin/2 fy:UB_TOP],
                                                                 [self.ubo fw:UB_WIDTH uw:-5.0/2*kSizeMallViewMargin ow:-kGoodsParametersCellLabelWidth fh:UB_HEIGHT])];
        
        
        self.valueLabel.textAlignment = NSTextAlignmentLeft;
        self.valueLabel.textColor = HZ_MALL_TEXT_M_LIGHTGRAY_COLOR;
        self.valueLabel.font = JKAppGlobleFontSmallTagText;
        self.valueLabel.numberOfLines = 0;
        
        [self addSubview:self.valueLabel];
        
       
    }
    return self;
}


- (void)showWithDictionry:(NSDictionary *)dict nameKey:(NSString *)nameKey valueKey:(NSString *)valueKey{
    if (dict.count) {
        [self.nameLabel setText:[NSString stringWithFormat:@"%@", [dict stringForKey:nameKey nilValue:@""]]];
        [self.valueLabel setText:[dict stringForKey:valueKey nilValue:@""]];
        CGFloat cellHeight = [NSString heightForString:[dict stringForKey:valueKey nilValue:@""] font:JKAppGlobleFontSmallTagText width:[self.ubo fw:UB_WIDTH uw:-5.0/2*kSizeMallViewMargin ow:-kGoodsParametersCellLabelWidth] maxHeight:9999.9f];
        if (cellHeight+kSizeMallViewMargin<kHZGoodsParametersCellHeight) {
            cellHeight = kHZGoodsParametersCellHeight;
        }
        self.valueLabel.frame = CGRectOf([self.nameLabel.ufo fx:UB_RIGHT ux:kSizeMallViewMargin/2 fy:UB_TOP oy:-3],
                                                                  [self.ubo fw:UB_WIDTH uw:-5.0/2*kSizeMallViewMargin ow:-kGoodsParametersCellLabelWidth oh:cellHeight+1]);
    }
}

@end
